<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import moment from '@/static/js/moment.js'
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				userId:"",
				editId:"",
				dataStr:"",
				subIndex:''
			})
		},
		methods:{
			onSelectStartTime(item){
				let _that = this 
				_that.$refs.autoform.clear("title1","endTime")
			},
			isTimeOverlay(sT,eT){
				let _that = this
				let arr = JSON.parse(_that.dataStr)
				let jarr = []
				for(let i in arr){
					arr[i].startTime += ':00'
					arr[i].endTime += ':00' 
					if(_that.subIndex != _that.autoformdata[0].order){
						jarr.push(arr[i])
					}
				}
				_that.om.request(
					"goOutWork/isTimeOverlay",{
						start:sT,
						end:eT,
						userId:_that.userId,
						editId: _that.editId,
						'dataStr':JSON.stringify(jarr)
					}
				).then(res=>{
					if(!res.succeed){
						if(!res.succeed){
							_that.om.toast(res.msg,3000)
							_that.$refs.autoform.clear("title1","endTime")
						}
					}
				})
			},
			onSelectActualEndDate(date){
				let _that = this
				if(_that.$refs.autoform.formdata.startTime){
					if(moment(date).isBefore(_that.$refs.autoform.formdata.startTime)){
						_that.$refs.autoform.clear("title1","endTime")
						let title1 = _that.$refs.autoform.getEditorTitle("title1",'startTime')
						let title2 = _that.$refs.autoform.getEditorTitle("title1",'endTime')
						_that.om.toast(title2+"应大于"+title1)
					}else{
						_that.isTimeOverlay(_that.$refs.autoform.formdata.startTime,date)
					}
				}
			}
		},
		onShow() {
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
				_that.userId = e.userId
				_that.editId = e.editId
				_that.dataStr = e.dataStr
				_that.subIndex = (Number(e.index)+1)
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							
							}
						}
					})
				}
				_that.$nextTick(function(){
					if(_that.$refs.autoform.formdata.startTime == _that.$refs.autoform.formdata.endTime){
						_that.$refs.autoform.clear("title1","endTime")
					}
				})
			})
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                         
